#include<stdio.h>
#include<malloc.h>

int i,n;
struct node{
            int info;
            struct node*next;
           };
struct node*first,*ptr;
void get_data(int ele)
{
ptr=malloc(sizeof(struct node));
ptr->info=ele;
ptr->next=first->next;
first->next=ptr;
}

void show_data()             /* Not showing the last element*/ 
{
 struct node *ptr3;
 int info2;
 ptr3=first;
 info2=ptr3->info; 
 printf("The new list is[%d,",info2);
 ptr3=ptr->next;
 for(;ptr3!=NULL;ptr3=ptr3->next)
 {
  info2=ptr3->info; 
  printf("%d,",info2);  
 }
}


void append(int ele2)
{ struct node *ptr2;
  ptr2=malloc(sizeof(struct node));  
  for(ptr2=first;ptr2->next!=NULL;ptr2=ptr2->next); 
  n++;
  first=realloc(first,n*sizeof(struct node));
  ptr->next=ptr2;
  ptr2->info=ele2;
  ptr2->next=NULL;
}  

void reverse()
{
 struct node *p,*q,*r;
p=malloc(sizeof(struct node));
q=malloc(sizeof(struct node));
r=malloc(sizeof(struct node));
p=ptr;
q=p->next;
r=q->next;
p->next->next=NULL;
while(r!=NULL)
{
 p=q;
q=r;
r=q->next;
q->next=p;
}
ptr->next=q;
}

void main()
{
 int ele,ch,c=1,ele2;
 int extn,extele;
 printf("Enter the size of the list");
 scanf("%d",&n); 
 first=malloc(n*sizeof(struct node));
 printf("Enter the element 1");
 scanf("%d",&first->info); 
 first->next=ptr;
 for(i=1;i<n;i++)
 {
  printf("Enter the element%d ",i+1);
  scanf("%d",&ele);
  get_data(ele);
 }
reverse();
show_data();
 while(c==1)
{
 printf("Enter your choice: \n1. Append\n2.Extend\n3.Insert\n4.remove\n5.pop\n6.Index \n7.Count \n8.Sort \n9.Reverse\n10.Exit\n");
 scanf("%d",&ch);
 switch(ch)
 { 
  case 1:printf("Enter the element to append\n");
         scanf("%d",&ele2); 
         get_data(ele2);
         reverse();
         show_data();
         break;
         
  case 2:reverse();
         printf("Enter the number of elements to extend the list with");
         scanf("%d",&extn); 
         for(i=0;i<n;i++)
         {
          printf("Enter the elements to be extended");
          scanf("%d",&extele);
          get_data(extele);
         }reverse();
         show_data();
         break;  
 case 9:reverse();
        show_data(); 
        break;
  }

 printf("Enter your choice (1 to re-enter the while loop and any other number to exit");
 scanf("%d",&c);
 
}
}

                    
